import React, { Component, PropTypes } from 'react';
import { connect } from 'dva';
import { routerRedux } from 'dva/router';
import { Grid, WhiteSpace } from 'antd-mobile';
import styles from './styles.less';

class ScaleListPage extends Component {
  constructor(props) {
    window.scrollTo(0, 0);
    // UI = render(data); 
    super(props);
    props.dispatch({ type: 'scale/reset' });
  }
  static defaultProps = {
    sheets: [
      {
        type: 'old',
        text: '老年人体质辨识',
        icon: require('../../../assets/icons/icon-sheet-old.svg'),
        module: 1,
      },
      {
        type: 'nine',
        text: '中医体质辨识',
        icon: require('../../../assets/icons/icon-sheet-physique.svg'),
        module: 2,
      },
       {
        type: 'tcm',
        text: '四诊合参体质辨识',
        icon: require('../../../assets/icons/icon-sheet-scientific.svg'),
        module: 12,
      },
      {
        type: 'prepre',
        text: '备孕女性健康状态测评',
        icon:  require('../../../assets/icons/icon-sheet-prepre.svg'),
        module: 14,

      },
      {
        type: 'normal',
        text: '常态女性健康状态测评',
        icon: require('../../../assets/icons/icon-sheet-normal.svg'),
        module: 16,
      },
      {
        type: 'pre',
        text: '孕期女性健康状态测评',
        icon: require('../../../assets/icons/icon-sheet-pregnancy.svg'),
        module: 4,
      },
      {
        type: 'partum',
        text: '产后女性健康状态测评',
        icon: require('../../../assets/icons/icon-sheet-postpartum.svg'),
        module: 13,
      },
      {
        type: 'chd',
        text: '儿童体质辨识',
        icon: require('../../../assets/icons/icon-sheet-children.svg'),
        module: 6,
      },
      {
        type: 'hyp',
        text: '高血压病辅助辨证',
        icon: require('../../../assets/icons/icon-sheet-hypertension.svg'),
        module: 5,
      },
      {
        type: 'dia',
        text: '糖尿病辅助辨证',
        icon: require('../../../assets/icons/icon-sheet-diabetes.svg'),
        module: 11,
      },
      {
        type: 'phy',
        text: '中医心理测评',
        icon: require('../../../assets/icons/icon-sheet-psychology.svg'),
        module: 3,
      },
      {
        type: 'phy2',
        text: '五态性格问卷测评',
        icon: require('../../../assets/icons/icon-sheet-psychology2.png'),
        module: 17,
      }],
    };

  goto(sheet) {
    const { dispatch, router, location, profile } = this.props;
    if (sheet.type) {
      dispatch(
        routerRedux.push({
          pathname: `${location.pathname}/family`,
          state: {
            title: sheet.text,
            type: sheet.type,
            profile,
          },
        }),
      );
    
    }
  }

  render() {
    const Modules  = this.props.profile.modules.split(";"); 
    const listPage = this.props.sheets;  let assess = [];
    for (var y = listPage.length - 1; y >= 0; y--) {     
        for (var i = Modules.length - 1; i >= 0; i--) {
          if( listPage[y].module == Modules[i]){
              listPage[y] ==  assess[assess.length];
              assess.unshift(listPage[y]);
          }
        }
    }
    return <Grid data={assess} columnNum={2} onClick={(sheet, i) => this.goto(sheet)} />;
  }
}

export default connect(({ profile }) => ({ profile }))(ScaleListPage);
